﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<html>
<head>
    <title></title>
    <link href="<s:url value='/common/lib/ligerUI/skins/Aqua/css/ligerui-all.css'/>" rel="stylesheet" type="text/css" />
    <script src="<s:url value='/common/lib/jquery/jquery-1.3.2.min.js'/>" type="text/javascript"></script>
    <script src="<s:url value='/common/lib/json2.js'/>" type="text/javascript"></script>
    <script src="<s:url value='/common/lib/ligerUI/js/core/base.js'/>" type="text/javascript"></script>
    <script src="<s:url value='/common/lib/ligerUI/js/plugins/ligerDialog.js'/>" type="text/javascript"></script>
    <script src="<s:url value='/common/lib/ligerUI/js/plugins/ligerTextBox.js'/>" type="text/javascript"></script>
    <script src="<s:url value='/common/lib/ligerUI/js/plugins/ligerCheckBox.js'/>" type="text/javascript"></script>
    <script src="<s:url value='/common/lib/ligerUI/js/plugins/ligerComboBox.js'/>" type="text/javascript"></script>
    <script src="<s:url value='/common/lib/ligerUI/js/plugins/ligerGrid.js'/>" type="text/javascript"></script>
    <script src="<s:url value='/common/lib/ligerUI/js/plugins/ligerDateEditor.js'/>" type="text/javascript"></script>
    <script src="<s:url value='/common/lib/ligerUI/js/plugins/ligerSpinner.js'/>" type="text/javascript"></script>
	<script src="<s:url value='/common/lib/ligerUI/js/plugins/ligerDrag.js'/>" type="text/javascript"></script> 
	<script src="<s:url value='/common/lib/ligerUI/js/plugins/ligerDialog.js'/>" type="text/javascript"></script>
    
    <script type="text/javascript">
        var userRoles = [{roleName:'admin', text:'管理员'}, {roleName:'monitor', text:'监督员'}, {roleName:'operator', text:'执行员'}];
        $(f_initGrid);
        var manager, g;
        function f_initGrid() {
            g = manager = $("#maingrid").ligerGrid({
                columns: [
                {display:'用户账号', name:'account', type:'text'},
                {display:'用户名', name:'name', editor:{type:'text'}},
				{display:'电话', name:'telephone', editor:{type:'text'}},
				{display:'Email', name:'email', editor: {type:'text'}},
                {display:'用户角色', name:'roleName', type:'text',
					editor:{ type:'select', data:userRoles, valueColumnName:'roleName' },
					render: function (item) {
                        if (item.roleName == 'admin') return '管理员';
						if (item.roleName == 'monitor') return '监督员';
                        return '执行员';
					}
                },
				{display:'操作',isSort:false,
					render:function (rowdata, rowindex, value) {
						var h = "";
						if (!rowdata._editing) {
							h += "<a href='javascript:beginEdit(" + rowindex + ")'>修改</a> ";
							h += "<a href='javascript:deleteRow(" + rowindex + ")'>删除</a> "; 
						} else {
							h += "<a href='javascript:endEdit(" + rowindex + ")'>提交</a> ";
							h += "<a href='javascript:cancelEdit(" + rowindex + ")'>取消</a> "; 
						}
						return h;
					 }
                }],
                onSelectRow:function (rowdata, rowindex)
                {
                    $("#txtrowindex").val(rowindex);
                },
                enabledEdit:true,
				clickToEdit:false, 
				isScroll:false,
                data:eval('(' + $("#userListJOSNStr").val() + ')'),
                width:720,
				
            });
        }
        function beginEdit(rowid) { 
            manager.beginEdit(rowid);
        }
        
        function cancelEdit(rowid) { 
            manager.cancelEdit(rowid);
        }
        
        function endEdit(rowid) {
        	var row = manager.getSelectedRow();
            manager.endEdit(rowid);
        	$.post("<s:url value='/user/updateUser.action'/>", {userId:row.id, userName:row.name, userTelePhone:row.telephone, userEmail:row.email, roleName:row.roleName});
        }
        
        function deleteRow(rowid) {
            $.ligerDialog.confirm('确定删除用户?', function (yes) {
            	if(yes) {
            		var row = manager.getSelectedRow();
            		$.post("<s:url value='/user/deleteUser.action'/>", {userId:row.id});
            		manager.deleteRow(rowid);
            	}
            });
        }
    </script>
</head>
<body  style="padding:10px">
	<s:hidden name="userListJOSNStr"/>
	<div class="l-clear"></div>
	<h3><s:text name="title.list.user"/></h3>
	
	<form id="findUsers" name="findUsers" method="post" action="/aim/user/findUsers.action">
		<div></div>
        <table cellpadding="0" cellspacing="0" class="l-table-edit" >
            <s:textfield name="userAccount" label="%{getText('label.user.account')}" cssStyle="border:1px solid #AECAF0; width: 130px; height:20px;"/>
        </table>
 		<br/>
		<input type="submit" value="<s:text name='button.query'/>" id="submitButton" class="l-button l-button-submit"/>
    </form>
	
    <div id="maingrid" style="margin-top:20px"></div>
    
   	<div style="display:none;"></div>
</body>
</html>